package com.ff.xyh.front.listener;

import com.ff.xyh.common.entity.post.PostImg;
import com.ff.xyh.feign.client.post.PostImgClient;
import com.ff.xyh.front.config.PostRabbitConfig;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalTime;

/**
 * @Auther FF
 * @Date 2022年 11月 13日
 * @Time 00:48
 */

@Component
public class PostRabbitListener {

    @Autowired
    private PostImgClient postImgClient;

    /**
     * 消费PostImg队列
     * @param postImg
     */
    @RabbitListener(queues = PostRabbitConfig.Queue_PostImg)
    public void postImgQueueConsumer1(PostImg postImg) {
        System.out.println("postImgQueueConsumer1 listenPostImgQueue received the message: {" + postImg + "}, when " + LocalTime.now());
        postImgClient.insertPostImg(postImg);
        System.out.println("finished");
    }

    @RabbitListener(queues = PostRabbitConfig.Queue_PostImg)
    public void postImgQueueConsumer2(PostImg postImg) {
        System.out.println("postImgQueueConsumer2 listenPostImgQueue received the message: {" + postImg + "}, when " + LocalTime.now());
        postImgClient.insertPostImg(postImg);
        System.out.println("finished");
    }


    /**
     * 消费PostImg死信队列
     * @param postImg
     */
    @RabbitListener(queues = PostRabbitConfig.Dead_Queue_PostImg)
    public void postImgDeadQueueConsumer(PostImg postImg) {
        System.out.println("listenPostImgDeadQueue received the message: {" + postImg + "}, when " + LocalTime.now());
    }

//    // 绑定队列并监听
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue( name = "directQ1"),
//            exchange = @Exchange(name = "directEx1", type = ExchangeTypes.DIRECT),
//            key = {"abc","cde"}
//    ))
//    public void listenDirectQ1(Object object) {
//        System.out.println("listenDirectQ1 received the message: {" + object + "}, when " + LocalTime.now());
//    }


}
